package logic

import (
	"context"
	"knowledge/models/mysqlinit"

	"knowledge/knowledgerpc/internal/svc"
	"knowledge/knowledgerpc/knowledgerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddKnowledgeLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddKnowledgeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddKnowledgeLogic {
	return &AddKnowledgeLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddKnowledgeLogic) AddKnowledge(in *knowledgerpc.AddKnowledgeRequest) (*knowledgerpc.AddKnowledgeResponse, error) {
	// todo: add your logic here and delete this line
	knowledge := mysqlinit.Knowledge{

		Title: in.Title,
		Click: int(in.Click),
		State: in.State,
	}
	err := mysqlinit.DB.Debug().Create(&knowledge).Error
	if err != nil {
		return nil, err
	}
	return &knowledgerpc.AddKnowledgeResponse{
		Id: int64(knowledge.ID),
	}, nil
}
